package com.hrl.controller;

import com.hrl.domain.Dept;
import com.hrl.domain.Employee;
import com.hrl.service.DeptService;
import com.hrl.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmpController {

    @Autowired
    private EmpService empService;

    @Autowired
    private DeptService deptService;

    @RequestMapping("/empsave")
    public String empSave(Employee employee){
        if(employee.getDept_id()==1){
            employee.setJob_name("客户经理");
        }else if(employee.getDept_id()==2){
            employee.setJob_name("销售经理");
        }
        empService.save(employee);

        return "success";
    }

    @RequestMapping(value="/deptfind",method = {RequestMethod.POST})
    public String deptFind(String id,Model model){
        Dept byId = deptService.findById(Integer.parseInt(id));

        model.addAttribute("dept",byId);
        return "../addEmp";
    }
}
